import Cookies from 'js-cookie'

interface AppState {
  sidebar: {
    opened: boolean
    withoutAnimation: boolean
  }
}

const state = {
  sidebar: {
    opened: Cookies.get('sidebarStatus') ? !!Number(Cookies.get('sidebarStatus')) : false,
    withoutAnimation: false
  }
}

const mutations = {
  TOGGLE_SIDEBAR: (state: AppState) => {
    state.sidebar.opened = !state.sidebar.opened
    state.sidebar.withoutAnimation = false
    if (state.sidebar.opened) {
      Cookies.set('sidebarStatus', '1')
    } else {
      Cookies.set('sidebarStatus', '0')
    }
  }
}

const actions = {
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
